import java.util.InputMismatchException;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        System.out.println("欢迎来到猜数字 ,请输入1-100之间的数字");
        Scanner scanner = new Scanner(System.in);
        int cai;
        while (true) {
            int change = 7;
            int da = (int) (Math.random() * 100 + 1);

            while (change > 0) {
                System.out.println("有" + change + "次机会");
                try {
                    cai = scanner.nextInt();
                } catch (InputMismatchException e) {
                    System.out.println("请输入数字");
                    scanner.next();
                    continue;
                }
                if (cai > da) {
                    System.out.println("大了");
                } else if (cai < da) {
                    System.out.println("小了");
                } else {
                    System.out.println("答对了");
                    break;
                }
                change--;

            }
            System.out.println("在玩一次吗y/n");
            String again = scanner.next();
            if (!again.equalsIgnoreCase("y")) {
                break;
            }
        }
    }
}